using System;
using System.Collections.Generic;
using System.Text;
using Hack.Authorization.Fault;
using System.ServiceModel;

namespace Hack.Authorization {
	/// <summary>
	/// Base class for all services of Digital Fortress.
	/// </summary>
	public class BaseService {
		#region IAdministrationService Members
		/// <summary>
		/// Indicates if Service is alive.
		/// </summary>
		/// <returns>Returns true.</returns>
		public bool Ping() {
			return true;
		}
		#endregion

		#region Throw Helper
		/// <summary>
		/// Gets a configured fault.
		/// </summary>
		/// <typeparam name="T">Type of the fault.</typeparam>
		/// <param name="reason">Reason of the fault.</param>
		/// <returns>Returns the configured fault.</returns>
		public FaultException<T> GetFault<T>(string reason) where T : DefaultFaultContract {
			T fault = Activator.CreateInstance<T>();
			fault.CorrelationId = Guid.Empty;
			fault.ErrorId = 0;
			fault.ErrorMessage = reason;
			return GetFault<T>(fault, reason);
		}
		/// <summary>
		/// Gets a configured fault.
		/// </summary>
		/// <typeparam name="T">Type of the fault.</typeparam>
		/// <param name="fault">Fault pre-configured.</param>
		/// <param name="reason">Reason.</param>
		/// <returns>Returns the fault.</returns>
		public FaultException<T> GetFault<T>(T fault, string reason) where T : DefaultFaultContract {
			FaultException<T> faultEx = (FaultException<T>)Activator.CreateInstance(typeof(FaultException<T>), new object[] { fault, reason });

			return faultEx;
		}
		#endregion Throw Helper
	}
}
